import maya.cmds  as mc

import LZ_public_command.LZ_controllar_command
reload( LZ_public_command.LZ_controllar_command )

import LZ_public_command.LZ_rename_command
reload( LZ_public_command.LZ_rename_command)

import LZ_public_command.LZ_general_command
reload(LZ_public_command.LZ_general_command)

import LZ_public_command.LZ_rivet
reload(LZ_public_command.LZ_rivet)

import LZ_public_command.LZ_skinCluster
reload(LZ_public_command.LZ_skinCluster)

import LZ_public_command.LZ_blendshape_command
reload(LZ_public_command.LZ_blendshape_command)

import LZ_public_command.LZ_sdk_command
reload(LZ_public_command.LZ_sdk_command)

import LZ_public_command.LZ_Attribute
reload(LZ_public_command.LZ_Attribute)

class pipeline_mdlar_facial(LZ_public_command.LZ_controllar_command.LZ_controllar_command , 
                            LZ_public_command.LZ_rename_command.rename_commands ,
                            LZ_public_command.LZ_general_command.general_command ,
                            LZ_public_command.LZ_rivet.LZ_rivetClass ,
                            LZ_public_command.LZ_skinCluster.LZ_skinCluster,
                            LZ_public_command.LZ_blendshape_command.LZ_blendshape_command,
                            LZ_public_command.LZ_sdk_command.LZ_sdk_command,
                            LZ_public_command.LZ_Attribute.LZ_attribute

                            ):
                            
    def __init__(self):
        pass
        
    def pipeline_UI(self):
        pipeline_UI = 'pipeline_UI'
        if mc.window(pipeline_UI,ex = True):
            mc.deleteUI(pipeline_UI)
            
        mc.window(pipeline_UI,widthHeight=(450, 400),t=pipeline_UI,menuBar = True,rtf=True,s=True)

        main = mc.columnLayout('mdlar_SDK_main',columnAttach=('both', 5), rowSpacing=10, columnWidth=450 )
        
        ###===========================================================================================================
        #-----------------------------------   eyeBrow  sdk setting    ---------------------------------------------
        
        mc.frameLayout( 'eyeBrow_SDK_frameLY',label='eyeBrow_SDK_mdlar', borderStyle='in',collapsable=False,bgc =(0.1,0.1,0.1) ,font = 'boldLabelFont')
        
        mc.text('please select the  "ac_lf_eyebrow_ctrl" and load to textField lower ')
        
        ##
        mc.rowLayout( 'loadEyeBrow_rowLY',numberOfColumns=3,columnWidth3=(100, 250,100), adjustableColumn=3, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (2, 'both', 0)])
        mc.text(  ' eyeBrow_prefix :  ')
        mc.textField( 'loadEyeBrow_SDK_textField',text='' )
        mc.button('load_eyeBrow' ,c = lambda *args:self.load_SDK_prefix(  mdlar = 'eyeBrow') )
        
        ##
        
        
        mc.setParent('eyeBrow_SDK_frameLY')
        mc.radioButtonGrp( 'eyeBrow_SDK_mdlar',label='eyeBrow_mdlar       ', labelArray3=['left', 'right', 'both'], numberOfRadioButtons=3,sl=3 )
        
        mc.rowLayout( 'eyeBrow_SDK_rowLY',numberOfColumns=3,columnWidth3=(100, 30,300), adjustableColumn=3, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (2, 'both', 0)])

        mc.textScrollList('eyeBrow_SDK_DriverList',allowMultiSelection=False, height =  155,width = 100,sc=lambda *args:self.EyeBrow_sdk_DRclickCommand())
        mc.columnLayout('eyeBrow_text_list',columnWidth=500)
        
        mc.setParent('eyeBrow_SDK_rowLY')
        mc.textScrollList('eyeBrow_SDK_DrivenList',allowMultiSelection=False, height =  155,width = 300,sc=lambda *args:self.EyeBrow_sdk_DVclickCommand())
        
        mc.setParent('eyeBrow_SDK_frameLY')
        mc.button('modify' ,c = lambda *args:self.EyeBrow_sdk_Modify(  ) )
        
        ###===========================================================================================================
        #-----------------------------------   mouth sdk setting    ---------------------------------------------
        
        mc.setParent( 'eyeBrow_SDK_frameLY')
        mc.frameLayout( 'mouth_SDK_frameLY',label='mouth_SDK_mdlar', borderStyle='in',collapsable=False,bgc =(0.1,0.1,0.1) ,font = 'boldLabelFont')
        mc.text('please select the  "ac_rt_mouth_ctrl" and load to textField lower ')
        
        ##
        mc.rowLayout( 'loadmouth_sdk_rowLY',numberOfColumns=3,columnWidth3=(100, 250,100), adjustableColumn=3, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (2, 'both', 0)])
        mc.text(  ' mouth_prefix :  ')
        mc.textField( 'loadMouth_SDK_textField',text='' )
        mc.button('load_mouth' ,c = lambda *args:self.load_SDK_prefix(  mdlar = 'mouth') )
        
        ##
        
        
        mc.setParent('mouth_SDK_frameLY')
        mc.radioButtonGrp( 'mouth_SDK_mdlar',label='mouth_side_      ', labelArray3=['left', 'right', 'both'], numberOfRadioButtons=3,sl=3 )
        
        mc.rowLayout( 'mouth_SDK_rowLY',numberOfColumns=3,columnWidth3=(100, 30,300), adjustableColumn=3, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (2, 'both', 0)])

        mc.textScrollList('mouth_SDK_DriverList',allowMultiSelection=False, height =  155,width = 100,sc=lambda *args:self.mouth_sdk_DRclickCommand())
        mc.columnLayout('mouth_text_list',columnWidth=500)
        
        mc.setParent('mouth_SDK_rowLY')
        mc.textScrollList('mouth_SDK_DrivenList',allowMultiSelection=False, height =  155,width = 300,sc=lambda *args:self.mouth_sdk_DVclickCommand())
        
        mc.setParent('mouth_SDK_frameLY')
        mc.button('mouth_modify' ,l='modify',c = lambda *args:self.mouth_sdk_Modify(  ) )
        
        
        ##================================================================================================================================
        #--------------  -------------------------------------------------
        for eyeBrowEmotion in [ 'up' , 'dn' ,'inn','out','front']:
            mc.textScrollList('eyeBrow_SDK_DriverList', e=True,append=eyeBrowEmotion)
            
        for mouthEmotion in [ 'open' ]:
            mc.textScrollList('mouth_SDK_DriverList', e=True,append=mouthEmotion)
        
        mc.showWindow(pipeline_UI)
        
        
        
        
    def getinputWireDeformer(self , inputMesh = '' ):
        inputHistory = mc.listHistory(inputMesh , lv =1 )
        wire_all = []
        for ih in inputHistory:
            if mc.nodeType(ih) == 'wire':
                wire_all.append(ih)
        
        return wire_all
        
        
    def setSkinValue_2_deformer_OnMesh( self , skinNode = '' , skinMesh = '' , wireMesh = '' ,infJoint = '', deformerNode = '' ):
    
        polyPoints = mc.polyEvaluate( skinMesh  ,v=True)
        for i in range(polyPoints) :
            infJnt = mc.skinPercent(skinNode,'%s.vtx[%s]' %(skinMesh,i),ignoreBelow=0.00001,query=True,t=None)#per model inf joint list
            jntWet = mc.skinPercent(skinNode,'%s.vtx[%s]' %(skinMesh,i),ignoreBelow=0.00001,query=True,v=True)#per joint weight
            
            num = 0
            for inj in infJnt:
                if inj == infJoint:
                    weight = jntWet[num]
                    mc.percent( deformerNode ,str(wireMesh)+'.vtx[' +str(i)+']' , v = weight ) 
                    #print( [str(mesh)+'.vtx[' +str(i)+']',deformerNode,jntWet[num]])
                else:
                    pass
                num = num+1
    

    def deformer_2_skin( self , skinNode = '' , skinMesh = '' , wireMesh = '' ,infJoint = '', deformerNode = '' ):
        polyPoints = mc.polyEvaluate( wireMesh  ,v=True)
        for i in range(polyPoints):
            weight = mc.percent( deformerNode ,str(wireMesh)+'.vtx[' +str(i)+']' , q=True ,v = True ) 
            
            mc.skinPercent(skinNode,'%s.vtx[%s]' %(skinMesh,i),ignoreBelow = 0.00001,tv = (infJoint, weight[0] ))#per model inf joint list    
            
            
    #def getCurve_FromWireNode(self, inputMesh = '' , wireNode = '' ):
        
        
    